﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Specialized;
using System.Collections.Generic;
using Xceed.Silverlight.Data.Stats;

namespace Xceed.Silverlight.Data
{
  internal class DataChangedEventArgs : EventArgs
  {
    internal DataChangedEventArgs()
    {
    }

    public DataChangedAction Action
    {
      get;
      private set;
    }

    public object NewItem
    {
      get;
      private set;
    }

    public object OldItem
    {
      get;
      private set;
    }


    public SourcePosition RemovePosition
    {
      get;
      private set;
    }

    public SourcePosition NewCurrentPosition
    {
      get;
      private set;
    }

    public IEnumerable<Tuple<object, object>> LoadedItems
    {
      get;
      private set;
    }

    public bool UpdateItems
    {
      get;
      private set;
    }

    public ItemChangedInfo ItemChangedInfo
    {
      get;
      private set;
    }

    public StatParameters StatParameters
    {
      get;
      private set;
    }


    internal DataChangedEventArgs( DataChangedAction action )
    {
      if(  action != DataChangedAction.Reset )
        throw new ArgumentException( "Only the Reset action is supported by this constructor.", "action" );

      this.Action = action;
    }

    internal DataChangedEventArgs( DataChangedAction action, object item )
    {
      if( action != DataChangedAction.Add )
        throw new ArgumentException( "Only the Add action is supported by this constructor.", "action" );

      this.Action = action;

      this.NewItem = item;
      this.OldItem = null;
    }

   internal DataChangedEventArgs( DataChangedAction action, object item, SourcePosition removePosition, SourcePosition newCurrentPosition )
    {
      if( action != DataChangedAction.Remove )
        throw new ArgumentException( "Only the Remove action is supported by this constructor.", "action" );

      this.Action = action;

      this.NewItem = null;
      this.OldItem = item;
      this.RemovePosition = removePosition;
      this.NewCurrentPosition = newCurrentPosition;
    }

     internal DataChangedEventArgs( DataChangedAction action, object newItem, object oldItem )
    {
      if( action != DataChangedAction.Replace )
        throw new ArgumentException( "Only the Replace action is supported by this constructor.", "action" );

      this.Action = action;
      this.NewItem = newItem;
      this.OldItem = oldItem;
    }

    public DataChangedEventArgs(DataChangedAction action, IList<Tuple<object,object>> loadedItems, bool updateItems)
    {
      if( action != DataChangedAction.ItemsLoaded )
        throw new ArgumentException( "Only the ItemsLoaded action is supported by this constructor.", "action" );

      this.Action = action;
      this.LoadedItems = loadedItems;
      this.UpdateItems = updateItems;
    }

    internal DataChangedEventArgs( DataChangedAction action, StatParameters statParameters, StatResults newStatResult, StatResults oldStatResult )
    {
      if( action != DataChangedAction.StatLoaded )
        throw new ArgumentException( "Only the StatLoaded action is supported by this constructor.", "action" );

      if( statParameters == null )
        throw new ArgumentNullException( "statParameters" );

      if( newStatResult == null )
        throw new ArgumentNullException( "newStatResult" );

      if( oldStatResult == null )
        throw new ArgumentNullException( "oldStatResult" );

      this.Action = action;
      this.StatParameters = statParameters;
      this.NewItem = newStatResult;
      this.OldItem = oldStatResult;
    }    

    public DataChangedEventArgs( ItemChangedInfo itemChangedInfo )
    {
      if( itemChangedInfo == null )
        throw new ArgumentNullException( "itemChangedInfo" );

      this.Action = DataChangedAction.ItemChanged;
      this.ItemChangedInfo = itemChangedInfo;
    }

    internal DataChangedEventArgs( 
      DataChangedAction action, 
      object newItem, 
      object oldItem, 
      SourcePosition removePosition, 
      SourcePosition newCurrentPosition, 
      ItemChangedInfo itemChangedInfo )
    {
      this.Action = action;
      this.NewItem = newItem;
      this.OldItem = oldItem;
      this.RemovePosition = removePosition;
      this.NewCurrentPosition = newCurrentPosition;
      this.ItemChangedInfo = itemChangedInfo;
    }
  }
}
